package com.zkdcloud.repository;

import com.zkdcloud.domain.BusinessActivity;
import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.SQL;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zk123
 * @version 2018/5/23
 */
@DB(table = "business_activity")
@Repository
public interface BusinessActivityDao {
    String COLUMNS = "id,business_id,name,icon_name,description,icon_color,create_time,price";

    /**
     * 添加商家活动
     *
     * @param businessActivity b
     */
    @SQL("insert into #table("+COLUMNS+") values(:id,:businessId,:name,:iconName,:description," +
            ":iconColor,:createTime,:price)")
    void add(BusinessActivity businessActivity);

    /**
     * 根据商家获取
     *
     * @param id id
     * @return 商家活动
     */
    @SQL("select * from #table where business_id = :1")
    List<BusinessActivity> getAllByBid(String id);

    @SQL("update #table set id = :id" +
            " #if(:name != null),name = :name #end" +
            " #if(:description != null),description = :description #end" +
            " #if(:iconName != null),icon_name = :iconName #end" +
            " #if(:iconColor != null),icon_color = :iconColor #end" +
            " #if(:price != null),price = :price #end" +
            " where id = :id")
    void update(BusinessActivity businessActivity);

    @SQL("delete from #table where id = :1")
    void remove(String id);
}
